#include"_queue.h"

void Print(Queue* queue)
{
	assert(queue);
	QueueNode* cur = queue->phead;
	while (cur)
	{
		printf("%d->", cur->val);
		cur = cur->next;
	}
	printf("\n");
}
void QueuePush(Queue* queue,QueueDataType x)
{
	assert(queue);
	QueueNode* newnode = (QueueNode*)malloc(sizeof(QueueNode));
	if (newnode == NULL) exit(-1);
	newnode->next = NULL;
	newnode->val = x;
	if (queue->phead ==NULL && queue->ptail == NULL) 
		queue->phead = queue->ptail = newnode;
	else
	{
		queue->ptail->next = newnode;
		queue->ptail = newnode;
	}
	queue->size++;
	
}
void QueueInit(Queue* queue)
{
	assert(queue);
	queue->phead = queue->ptail = NULL;
	queue->size = 0;
}
void QueuePop(Queue* queue)
{
	assert(queue);
	queue->phead = queue->phead->next;
	queue->size--;
}
void QueueDestroy(Queue* queue)
{
	assert(queue);
	QueueNode* cur = queue->phead;
	while (cur)
	{
		QueueNode* next = cur->next;
		free(cur);
		cur = next;
	}
}